package com.jd.sys.controller;

import com.jd.basic.util.AjaxResult;
import com.jd.basic.util.PageList;
import com.jd.org.domain.Department;
import com.jd.org.domain.Employee;
import com.jd.org.query.DepartmentQuery;
import com.jd.sys.domain.DictionaryDetail;
import com.jd.sys.domain.DictionaryType;
import com.jd.sys.query.DictionaryDetailQuery;
import com.jd.sys.service.IDictionaryDetailService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/dictionary")
@Api(value = "数据字典", description = "数据字典相关的CRUD功能")
public class DictionaryDetailController {
    @Autowired
    IDictionaryDetailService service;
    /**
     * 分页查询
     */
    @PostMapping()
    public PageList<DictionaryDetail> queryByPage(@RequestBody DictionaryDetailQuery query) {
        System.err.println("查询=========="+ query);
        return service.queryByPage(query);
    }

    @GetMapping("/type")
    public DictionaryType getDictionaryType(){
        DictionaryType dictionaryType =service.getDictionaryType();
        return dictionaryType;
    }

    @PutMapping()
    public AjaxResult addOrUpdate(@RequestBody DictionaryDetail detail) {
        System.err.println("测试测试Controller" + detail);
        if (null != detail.getId()) {
            // 修改
            service.update(detail);
        } else {
            // 添加
            service.add(detail);
        }
        return AjaxResult.me().success();
    }

    /**
     * 删除
     */
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id") Long id) {
        System.err.println("删除方法" + id);
        service.delete(id);
        return AjaxResult.me().success();
    }

    @PatchMapping
    public AjaxResult batchDelete(@RequestBody List<Long> ids) {
        System.err.println("批量删除测试" + ids);
        service.batchDelete(ids);
        return  AjaxResult.me().success();
    }

    @GetMapping("/{id}")
    public List<DictionaryDetail> findEmpByDeptId(@PathVariable Long id){
        System.err.println("进入Controller" + id);
        return service.findDetailByDeptId(id);
    }
}
